package Homework4;

class WrongData extends Exception {
    WrongData(String message) {
        super(message);
    }
}

public class Score {
    private double[] _scores;

    Score(double[] scores) {
        _scores = scores;
    }

    boolean isWrongData() {
        for (double i : _scores) {
            if (i > 100 || i < 0) {
                return true;
            }
        }
        return false;
    }

    public double max() {
        double maxNum = 0;
        for (double i : _scores) {
            if (i > maxNum) {
                maxNum = i;
            }
        }
        return maxNum;
    }

    public double min() {
        double minNum = 100;
        for (double i : _scores) {
            if (i < minNum) {
                minNum = i;
            }
        }
        return minNum;
    }

    public double average() {
        double sum = 0;
        int cnt = 0;
        for (double i : _scores) {
            sum += i;
            cnt++;
        }
        return sum / cnt;
    }

    public static void main(String[] args) {
        try {
            double[] sc1 = {85, 86, 87.5, 92.5, 94, 95};
            double[] sc2 = {-20, 102, 88};
            Score s1 = new Score(sc1);
            Score s2 = new Score(sc2);
            if (s1.isWrongData()) {
                throw new WrongData("分数错误");
            } else {
                System.out.println("s1最大值为" + s1.max() + ",最小值为" + s1.min() + ",平均值为" + s1.average());
            }
            
            if (s2.isWrongData()) {
                throw new WrongData("分数错误");
            } else {
                System.out.println("s2最大值为" + s2.max() + ",最小值为" + s2.min() + ",平均值为" + s2.average());
            }
        } catch (WrongData e) {
            System.out.println(e.getMessage());
        }
    }
}
